/*
 * License GNU LGPL
 * Copyright (C) 2012 Amrullah <amrullah@panemu.com>.
 */
package com.abc.cheque.ui;


import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;

import com.abc.cheque.entity.Contact;
import com.abc.cheque.ui.dialog.MessageDialog;
import com.abc.cheque.ui.dialog.MessageDialog.Answer;
import com.abc.cheque.ui.dialog.MessageDialogBuilder;
import com.abc.cheque.ui.table.TableControl;
import com.abc.cheque.ui.table.TableController;

/**
 *
 * @author Amrullah <amrullah@panemu.com>
 */
public class FrmContactTable2 extends FrmContactTable {

    public FrmContactTable2(TableController<Contact> controller) {
        super(controller);
    }

    @Override
    protected void init() {
        super.init();
        
        // Add button in TableControl's toolbar
        Button button = ButtonBuilder.create()
                .graphic(new ImageView(new Image(TableControl.class.getResourceAsStream("/images/chart.png"))))
                .build();
        
        button.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                Answer answer = MessageDialogBuilder.info().message("message.one")
                        .yesOkButtonText("I know")
                        .noButtonText("No, I don't")
                        .buttonType(MessageDialog.ButtonType.YES_NO)
                        .show(FrmContactTable2.this.getScene().getWindow());
                if (answer == Answer.NO) {
                    MessageDialogBuilder.info().message("Maybe the developer hid it.")
                            .show(FrmContactTable2.this.getScene().getWindow());
                }
            }
        });
        tblContact.addButton(button);
        
        // Hide delete button
        tblContact.setVisibleComponents(false, TableControl.Component.BUTTON_DELETE);
        
        // Add menu item to TableControl's context menu
        tblContact.addContextMenuItem("Custom Menu Item", new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                //Show the MessageDialog later to give a chance for popup to close it self.
                Platform.runLater(new Runnable() {

                    @Override
                    public void run() {
                        MessageDialogBuilder.warning().buttonType(MessageDialog.ButtonType.YES_NO_CANCEL)
                        .title("Custom Context Menu Item")
                        .message("You just clicked custom context menu item.")
//                        .yesOkButtonText("Yes Text")
                        .noButtonText("no.text")
                        .cancelButtonText("Cancel Text")
                        .show(FrmContactTable2.this.getScene().getWindow());
                    }
                });
            }
        });
    }
 
}
